import requests
from datetime import datetime
from requests_toolbelt.multipart.encoder import MultipartEncoder

class MetadataSender:
    def send_metadata(
        self,
        api_url: str,
        camera_name: str,
        video_name: str,
        timeout: int = 400000
    ) -> requests.Response:
        """
        发送纯元数据到API
        
        参数:
            api_url: 接收请求的API地址
            camera_name: 摄像头名称(对应接口中的cameraName)
            video_name: 视频名称(对应接口中的name)
            timeout: 请求超时时间(毫秒)
        """
        # 准备元数据表单
        fields = {
            "cameraName": camera_name,
            "isLast": "1",  # 修复缺少的逗号
            "name": video_name,
            "quickRemarks": "本次视频时长1小时,发现2次机动车违章行为,违章率0.5%",
        }

        encoder = MultipartEncoder(fields=fields)
        
        response = requests.post(
            api_url,
            data=encoder,
            headers={'Content-Type': encoder.content_type},
            timeout=timeout/1000  # 转换为秒
        )
        return response

# 使用示例
if __name__ == "__main__":
    sender = MetadataSender()
    
    response = sender.send_metadata(
        api_url="http://192.168.0.142:80/aiApi/saveQuickInfo",
        camera_name="chunk_0000",
        video_name="chunk_0000"
    )
    
    print(f"请求状态码: {response.status_code}")
    print(f"响应内容: {response.text}")